import { View, Text, Button } from "@tarojs/components";
import Taro, { useLoad } from "@tarojs/taro";
import "./index.less";

export default function Index() {
  useLoad(() => {
    const userInfo = Taro.getStorageSync("userInfo");
    if (!userInfo) {
      // 未登录，跳转到登录页面
      Taro.navigateTo({
        url: "/pages/login/index",
      });
    } else {
      console.log("已登录用户信息:", userInfo);
    }
  });
  const gotoOtherPage = (url: string) => {
    Taro.navigateTo({
      url: `/pages/${url}/index`,
    });
  };
  return (
    <View className="index">
      <Text>这是首页</Text>
      <Button onClick={() => gotoOtherPage("my")}>跳转到其他页面</Button>
      <Button onClick={() => gotoOtherPage("login")}>跳转到登录页面</Button>
    </View>
  );
}
